﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IFSModel
{
    public class MemberLeagueSummary
    {
        public string LeagueID { get; set; }
        public string LeagueName { get; set; }
        public int MemberLeagueRank  { get; set; }
        public int MemberLeagueScore { get; set; }
        public int MemberLeagueScoreMonth { get; set; }
        public List<long?> Last10Result { get; set; }
    }

    public class MemberRank
    {
        public long MemID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public decimal? Curent_Star { get; set; }
        public decimal? Score { get; set; }
        public long? ScoreMonth { get; set; }
        public int count { get; set; }
        public DateTime? Createdate { get; set; }
    }
    public partial class Members_play
    {
        public bool calMatchPoint(out decimal retpoint, out decimal retstar)
        {

            //Rdiff = teamAscore - teamBscore
            //Diff = rDiff - Handicap
            //Win full  : Diff >= 0.5
            //Win half  : Diff = 0.25
            //Draw      : Diff = 0
            //Lost full : Diff <= -0.5
            //Lost half : Diff = -0.25
             
            decimal Rdiff = 0;
            decimal Diff = 0;
            decimal Calfinalpoint = 0;
            decimal Calstar = 0;


            if (Current_TeamHandicap.ToString().ToLower() == "livea" && Selectteam.ToString().ToLower() == "livea") // selected team A ทีมต่อ
            {
                Rdiff = (Convert.ToInt32(_ScoreA) - Convert.ToInt32(_ScoreB));
                Diff = Rdiff - Convert.ToDecimal(Current_PriceHandicap);
            }
            else if (Current_TeamHandicap.ToString().ToLower() == "livea" && Selectteam.ToString().ToLower() == "liveb") // selected team b ทีมรอง
            {
                Rdiff = (Convert.ToInt32(_ScoreB) - Convert.ToInt32(_ScoreA));
                Diff = Rdiff + Convert.ToDecimal(Current_PriceHandicap);
            }
            else if (Current_TeamHandicap.ToString().ToLower() == "liveb" && Selectteam.ToString().ToLower() == "liveb") // selected team b ทีมต่อ
            {
                Rdiff = (Convert.ToInt32(_ScoreB) - Convert.ToInt32(_ScoreA));
                Diff = Rdiff - Convert.ToDecimal(Current_PriceHandicap);
            }
            else if (Current_TeamHandicap.ToString().ToLower() == "liveb" && Selectteam.ToString().ToLower() == "livea") // selected team a ทีมรอง
            {
                Rdiff = (Convert.ToInt32(_ScoreA) - Convert.ToInt32(_ScoreB));
                Diff = Rdiff + Convert.ToDecimal(Current_PriceHandicap);
            }
            //==================================================================

            if (Convert.ToDouble(Diff) >= 0.5) // Winfull
            {
                Calfinalpoint = 2;
                Calstar = Convert.ToDecimal(StarBet) + Convert.ToDecimal(StarBet);
            }
            else if (Convert.ToDouble(Diff) == 0.25) // Winhalf
            {
                Calfinalpoint = 1;
                Calstar = Convert.ToDecimal(StarBet) + (Convert.ToDecimal(StarBet) / 2);
            }
            else if (Convert.ToDouble(Diff).Equals(0)) //Draw
            {
                Calfinalpoint = 0;
                Calstar = Convert.ToDecimal(StarBet);
            }
            else if (Convert.ToDouble(Diff) <= -0.5) // Lostfull
            {
                Calfinalpoint = -2;
                Calstar = (Convert.ToDecimal(StarBet)) * -1;
            }
            else if (Convert.ToDouble(Diff) == -0.25) // Losthalf
            {
                Calfinalpoint = -1;
                Calstar = (Convert.ToDecimal(StarBet) / 2) * -1;
            }

            retpoint = Calfinalpoint;
            retstar = Calstar;

            return true;

        }

        #region old
        //public bool calMatchPoint(out decimal retpoint, out decimal retstar)
        //{
        //    if (Current_PriceHandicap.Equals(0))
        //    { }
        //    else
        //        Current_PriceHandicap = Current_PriceHandicap * -1;

        //    //===================================================================
        //    //if (Current_PriceHandicap > 1)
        //    //{
        //    //    Current_PriceHandicapStr = Convert.ToString(Current_PriceHandicap);
        //    //    Current_PriceHandicapStr = Right(Current_PriceHandicapStr, 2);
        //    //    Current_PriceHandicapStr = "0." + Current_PriceHandicapStr;
        //    //    Current_PriceHandicap = Convert.ToDecimal(Current_PriceHandicapStr);
        //    //}



        //    decimal Calresult = 0;
        //    double EPSILON = 0.000001;
        //    decimal Calfinalpoint = 0;

        //    if (Current_TeamHandicap.ToString().ToLower().Equals(Selectteam.ToString().ToLower())) // selected team ต่อ
        //    {
        //        Calresult = (Convert.ToInt32(_ScoreA) - Convert.ToInt32(_ScoreB)) - Current_PriceHandicap ?? 0;

        //        if (Calresult > 0)
        //        {
        //            if (Math.Abs((double)Calresult - (0.25)) < EPSILON)
        //                Calfinalpoint = 1; // half point = 1
        //            else
        //                Calfinalpoint = 2;
        //        }
        //        else if (Calresult.Equals(0))
        //            Calfinalpoint = 0; // tie = 0
        //        else if (Calresult < -0)
        //        {
        //            if (Math.Abs((double)Calresult - (-0.25)) < EPSILON)
        //            {
        //                if (Calresult < -0)
        //                {
        //                    Calfinalpoint = -1; // lose half point = 1  
        //                }
        //                else
        //                {
        //                    Calfinalpoint = 1; // get half point = 1  
        //                }
        //            }
        //            else
        //                Calfinalpoint = -2;
        //        }
        //        else
        //            Calfinalpoint = 1; // half point = 1
        //    }
        //    else //=======================================// selected team รอง
        //    {
        //        Calresult = (Convert.ToInt32(_ScoreA) - Convert.ToInt32(_ScoreB)) - Current_PriceHandicap ?? 0;

        //        if (Calresult > 0)
        //        {
        //            if (Math.Abs((double)Calresult - (0.25)) < EPSILON)
        //                Calfinalpoint = 1; // half point = 1
        //            else
        //                Calfinalpoint = 2;
        //        }
        //        else if (Calresult.Equals(0))
        //        {
        //            if ((Current_PriceHandicap - (-2) >= 4))
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else
        //                Calfinalpoint = 0;
        //        }
        //        else if (Calresult < -0)
        //        {
        //            if (Math.Abs((double)Calresult - (-0.25)) < EPSILON)
        //            {
        //                if (Calresult < -0)
        //                {
        //                    Calfinalpoint = 1; // lose half point = 1  
        //                }
        //                else
        //                {
        //                    Calfinalpoint = 1; // get half point = 1  
        //                }
        //            }
        //            else if (Math.Abs((double)Calresult - (-0.50)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-0.75)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-1)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-1.25)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-1.50)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-1.75)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-2)) < EPSILON)
        //            {
        //                //Calfinalpoint = 0;
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-2.25)) < EPSILON)
        //            {
        //                Calfinalpoint = 1;
        //            }
        //            else if (Math.Abs((double)Calresult - (-2.50)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-2.75)) < EPSILON)
        //            {
        //                Calfinalpoint = 2;
        //            }
        //            else if (Math.Abs((double)Calresult - (-3.75)) < EPSILON)
        //            {
        //                Calfinalpoint = -1;
        //            }
        //            else if (Math.Abs((double)Calresult - (-4.25)) < EPSILON)
        //            {
        //                Calfinalpoint = 1;
        //            }
        //            else
        //                Calfinalpoint = -2;
        //        }
        //        else
        //            Calfinalpoint = 1; // half point = 1


        //    }
        //    retpoint = Calfinalpoint;
        //    retstar = StarBet ?? 0 * Calfinalpoint;
        //    return true;
        //}

        #endregion
        

    }

}
